package com.etime.shuhuiyuan.controllers.courseadmin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.dto.CourseAdminDto;
import com.etime.shuhuiyuan.pojo.Course;
import com.etime.shuhuiyuan.pojo.Teacher;
import com.etime.shuhuiyuan.services.courseadmin.interfaces.CourseAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "course管理员管理接口")
@RestController
@RequestMapping("/courseadmin")
public class CourseAdminController {

    @Autowired
    private CourseAdminService courseAdminService;

    @ApiOperation("查询course列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="coursetitle",value="传递字符串"),
    })
    @GetMapping("/list")
    public ListMessage<Course> selectDemoList(Course course){
        ListMessage<Course> listMessage = new ListMessage<>();
        List<Course> list = courseAdminService.selectCourseList(course);
        if(list!=null) {
            listMessage.setDatalist(list);
            listMessage.setCode(1);
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }

    @ApiOperation("分页查询course案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseid", value = "传递数字"),
            @ApiImplicitParam(name = "coursetitle", value = "通过标签查询"),
            @ApiImplicitParam(name = "pageNum", value = "第几页"),
            @ApiImplicitParam(name = "pageSize", value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<Course> selectTeacherByPage(Course course, Long pageNum, Long pageSize) {
        PageMessage<Course> msg = new PageMessage<>();
        Page<Course> pageData = courseAdminService.selectCourseListByPage(course, pageNum, pageSize);
        if (pageData != null) {
            msg.setCode(1);
            msg.setPagedata(pageData);
        } else {
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("分页查询course案例2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "传递数字"),
            @ApiImplicitParam(name = "orgname", value = "通过标签查询"),
            @ApiImplicitParam(name = "pageNum", value = "第几页"),
            @ApiImplicitParam(name = "pageSize", value = "每页多少行")}
    )
    @GetMapping("/page2")
    public PageMessage<CourseAdminDto> selectTeacherByPage(CourseAdminDto courseAdminDto, Long pageNum, Long pageSize) {
        PageMessage<CourseAdminDto> msg = new PageMessage<>();
        Page<CourseAdminDto> pageData = courseAdminService.selectCourseAdminDtoByPage(courseAdminDto, pageNum, pageSize);
        if (pageData != null) {
            msg.setCode(1);
            msg.setPagedata(pageData);
        } else {
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据id查询一条course信息的案例")
    @ApiImplicitParam("courseid")
    @GetMapping("/get/{courseid}")
    public PojoMessage<CourseAdminDto> selectCourseAdminDtoById(@PathVariable("courseid") int courseid){
        PojoMessage<CourseAdminDto> msg = new PojoMessage<>();
        CourseAdminDto courseAdminDto = courseAdminService.selectCourseAdminDtoById(courseid);
        if(courseAdminDto!=null){
            msg.setCode(1);
            msg.setData(courseAdminDto);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }

    @ApiOperation("修改course案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="courseid",value = "主键，必须传递"),
            @ApiImplicitParam(name="coursetypeid",value = "课程类型id"),
            @ApiImplicitParam(name="coursetitle",value="课程title"),
            @ApiImplicitParam(name="courseteacherid",value="课程教师id"),
            @ApiImplicitParam(name="courseorgid",value="课程机构id"),
            @ApiImplicitParam(name="courseteachername",value="课程教师姓名")
    })
    @PostMapping("/update")
    public BaseMessage updateCourseAdmin(Course course){
        BaseMessage msg = new BaseMessage();
        int rtn = courseAdminService.updateCourseAdmin(course);
        msg.setCode(rtn);
        if (rtn > 0) {
            msg.setMsg("保存course成功");
        } else {
            msg.setMsg("保存course失败");
        }
        return msg;
    }
}
